package mao.leetcode.dp.leetcode64;

public class Solution {

    public static void main(String[] args) {
      //  int[][] a = [[1,3,1],[1,5,1],[4,2,1]]

    }
    public int minPathSum(int[][] grid) {
        boolean flag = true;
        int[] cur = new int[grid[0].length];
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (i == 0) {
                    if (j == 0) {
                        cur[j] = grid[0][j];
                        continue;
                    }else {
                        cur[j] = cur[j-1]+grid[0][j];
                        continue;
                    }
                } else if (j==0) {
                    cur[j]+=grid[i][j];
                    continue;
                }
                cur[j]= Math.min(cur[j-1],cur[j])+grid[i][j];
            }
        }
        return cur[grid[0].length-1];
    }
}
